﻿using System;
using Glue;
using GlueTests.Builders;
using Xunit;

namespace GlueTests.MappingTests
{
    public class When_flattening_towards_right
    {
        private readonly Mapping<DomainPerson, GuiPerson> personMapping;

        public class GuiPerson
        {
            public String Name { get; set; }
            public String City { get; set; }
        }

        public class DomainPerson
        {
            public String Name { get; set; }
            public DomainAddress Address { get; set; }
        }

        public class DomainAddress
        {
            public String City { get; set; }
        }

        public When_flattening_towards_right()
        {
            personMapping = new Mapping<DomainPerson, GuiPerson>();
            var addressMapping = new Mapping<DomainAddress, GuiPerson>();
            personMapping.Flatten(domain => domain.Address, addressMapping);
        }

        [Fact]
        public void Should_accept_relation()
        {
            var relations = personMapping.Relations;
            Assert.True(relations.IsRelatedTowardsOnLeftSide(new PropertyBuilder(typeof(DomainPerson), "Address").Build())); 
        }
    }
}